home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include "exinterfmotif.h"
- #include <gl.h>
- #include <gl/image.h>
- #include <string.h>
- #include "exglobals.h"
- #include "exbookglo.h"
- #define NULLCHARPTR (char *)0
-
- float tex_props[] = {TX_MINFILTER,TX_MIPMAP_BILINEAR,
- TX_MAGFILTER,TX_BILINEAR,TX_NULL};
- float env_props[] = {TV_NULL};
-
- static long next_tex_id = 1;
- static void (*i_errfunc)();
-
-
- void init_texture(struct icntmpltstruct *iconptr)
- {
- long id = 1;
-
- texdef2d(iconptr->tex_id, 4, iconptr->tex_width,
- iconptr->tex_height, iconptr->tex_image, 5, tex_props);
- tevdef(id,1,env_props);
- }
-
- void readicon_i(struct icntmpltstruct *iconptr)
- {
- unsigned long *lptr;
- short *rbuf, *gbuf, *bbuf, *abuf;
- char strgin[50];
- char *outstrg1;
- char *outstrg2;
- IMAGE *image;
- int y;
- char *fname;
-
- /* Make sure bad image files or improper image names don't crash
- and burn the program.... */
- strcpy(strgin,iconptr->imgfile->name);
- /* printf("iopen...strgin = %s\n",strgin); */
-
- /* if ((outstrg1 = strstr(strgin,".rgb")) == NULLCHARPTR) {
- printf("not a valid image file....%s\n",outstrg1);
- iconptr->imgfile = NULL;
- return;
- } */
- /* if ((outstrg2 = strstr(strgin,".icon")) == NULLCHARPTR) {
- printf("not a valid image file....%s\n",outstrg2);
- iconptr->imgfile = NULL;
- return;
- } */
- if (demoenv != NULL && strncmp("$DEMOS", iconptr->imgfile->name, 6) == 0)
- {
- fname = (char *)malloc(demoenvlen + strlen(iconptr->imgfile->name) );
- strcpy(fname, demoenv);
- strcpy(&(fname[demoenvlen]), &(iconptr->imgfile->name[6]));
- }
- else if (xenv != NULL && strncmp("$XDEMOS",iconptr->imgfile->name, 7) == 0)
- {
- fname = (char *)malloc(xenvlen + strlen(iconptr->imgfile->name) );
- strcpy(fname, xenv);
- strcpy(&(fname[xenvlen]), &(iconptr->imgfile->name[7]));
- }
- else if (sbenv != NULL && strncmp("$SBIN", iconptr->imgfile->name, 5) == 0)
- {
- fname = (char *)malloc(sbenvlen + strlen(iconptr->imgfile->name) );
- strcpy(fname, sbenv);
- strcpy(&(fname[sbenvlen]), &(iconptr->imgfile->name[5]));
- }
- else
- {
- fname = (char *)malloc(1 + strlen(iconptr->imgfile->name) );
- strcpy(fname, iconptr->imgfile->name);
- }
- /*
- image = iopen(iconptr->imgfile->name,"r");
- */
- image = iopen(fname,"r");
- free(fname);
- if(!image)
- {
- sprintf(msgstring, "\nDemo %s\n Invalid image icon file :\n%s",
- iconptr->nameptr->string, iconptr->imgfile->name);
- popup_Message();
- handleMessageEvents();
- iconptr->imgfile = NULL;
- return;
- }
- else
- {
- iconptr->tex_image = (unsigned long *)malloc(image->xsize*image->ysize*sizeof(unsigned long));
- rbuf = (short *)malloc(image->xsize*sizeof(short));
- gbuf = (short *)malloc(image->xsize*sizeof(short));
- bbuf = (short *)malloc(image->xsize*sizeof(short));
- abuf = (short *)malloc(image->xsize*sizeof(short));
- if(!iconptr->tex_image || !rbuf || !gbuf || !bbuf) {
- fprintf(stderr,"reading icon image file : can't malloc enough memory\n");
- iclose(image);
- iconptr->imgfile = NULL;
- return;
- }
- else
- {
- iconptr->tex_width = image->xsize;
- iconptr->tex_height = image->ysize;
- iconptr->tex_id = next_tex_id;
- next_tex_id++;
- lptr = iconptr->tex_image;
- for(y=0; y<image->ysize; y++) {
- if(image->zsize>=4)
- {
- getrow(image,rbuf,y,0);
- getrow(image,gbuf,y,1);
- getrow(image,bbuf,y,2);
- getrow(image,abuf,y,3);
- rgbatocpack(rbuf,gbuf,bbuf,abuf,lptr,image->xsize);
- lptr += image->xsize;
- }
- else if(image->zsize==3)
- {
- getrow(image,rbuf,y,0);
- getrow(image,gbuf,y,1);
- getrow(image,bbuf,y,2);
- rgbtocpack(rbuf,gbuf,bbuf,lptr,image->xsize);
- lptr += image->xsize;
- }
- else
- {
- getrow(image,rbuf,y,0);
- bwtocpack(rbuf,lptr,image->xsize);
- lptr += image->xsize;
- }
- }
- }
- iclose(image);
- free(rbuf);
- free(gbuf);
- free(bbuf);
- free(abuf);
- init_texture(iconptr);
- }
- }
-
-
- bwtocpack(b,l,n)
- register unsigned short *b;
- register unsigned long *l;
- register int n;
- {
- while(n>=8) {
- l[0] = 0x00010101*b[0];
- l[1] = 0x00010101*b[1];
- l[2] = 0x00010101*b[2];
- l[3] = 0x00010101*b[3];
- l[4] = 0x00010101*b[4];
- l[5] = 0x00010101*b[5];
- l[6] = 0x00010101*b[6];
- l[7] = 0x00010101*b[7];
- l += 8;
- b += 8;
- n -= 8;
- }
- while(n--)
- *l++ = 0x00010101*(*b++);
- }
-
- rgbtocpack(r,g,b,l,n)
- register unsigned short *r, *g, *b;
- register unsigned long *l;
- register int n;
- {
- while(n>=8) {
- l[0] = r[0] | (g[0]<<8) | (b[0]<<16);
- l[1] = r[1] | (g[1]<<8) | (b[1]<<16);
- l[2] = r[2] | (g[2]<<8) | (b[2]<<16);
- l[3] = r[3] | (g[3]<<8) | (b[3]<<16);
- l[4] = r[4] | (g[4]<<8) | (b[4]<<16);
- l[5] = r[5] | (g[5]<<8) | (b[5]<<16);
- l[6] = r[6] | (g[6]<<8) | (b[6]<<16);
- l[7] = r[7] | (g[7]<<8) | (b[7]<<16);
- l += 8;
- r += 8;
- g += 8;
- b += 8;
- n -= 8;
- }
- while(n--)
- *l++ = *r++ | ((*g++)<<8) | ((*b++)<<16);
- }
-
- rgbatocpack(r,g,b,a,l,n)
- register unsigned short *r, *g, *b, *a;
- register unsigned long *l;
- register int n;
- {
- while(n>=8) {
- l[0] = r[0] | (g[0]<<8) | (b[0]<<16) | (a[0]<<24);
- l[1] = r[1] | (g[1]<<8) | (b[1]<<16) | (a[1]<<24);
- l[2] = r[2] | (g[2]<<8) | (b[2]<<16) | (a[2]<<24);
- l[3] = r[3] | (g[3]<<8) | (b[3]<<16) | (a[3]<<24);
- l[4] = r[4] | (g[4]<<8) | (b[4]<<16) | (a[4]<<24);
- l[5] = r[5] | (g[5]<<8) | (b[5]<<16) | (a[5]<<24);
- l[6] = r[6] | (g[6]<<8) | (b[6]<<16) | (a[6]<<24);
- l[7] = r[7] | (g[7]<<8) | (b[7]<<16) | (a[7]<<24);
- l += 8;
- r += 8;
- g += 8;
- b += 8;
- a += 8;
- n -= 8;
- }
- while(n--)
- *l++ = *r++ | ((*g++)<<8) | ((*b++)<<16) | ((*a++)<<24);
- }
-
-